package org.new9uy.tetris;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.GraphicsEnvironment;
import java.awt.event.KeyEvent;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.border.LineBorder;

import org.new9uy.tetris.util.SwingUtils;
import org.new9uy.tetris.view.Menu;

public class GameConstants
{
	public static final Color
		TETRIMINO_COLOR_O = Color.YELLOW;
	public static final Color
		TETRIMINO_COLOR_T = Color.MAGENTA;	
	public static final Color
		TETRIMINO_COLOR_I = Color.CYAN;
	public static final Color
		TETRIMINO_COLOR_S = Color.GREEN;
	public static final Color
		TETRIMINO_COLOR_Z = Color.RED;
	public static final Color
		TETRIMINO_COLOR_J = Color.BLUE;
	public static final Color
		TETRIMINO_COLOR_L = Color.ORANGE;
	
	
	public static final int
		MIDIPLAYER_DEFAULT_TEMPO = 150;
	
	
	public static final Color 
		MINO_EMPTY_COLOR = new Color(0,0,0,255);
	public static final Color
		MINO_BLINK_COLOR = Color.WHITE;
	public static final Color
		MINO_LINESPAWN_COLOR = new Color(200,200,0);
	public static final LineBorder 
		MINO_BORDER = new LineBorder(new Color(0,0,0,100), 1);
	public static final Dimension
		MINO_PREFERRED_DIMENSION = new Dimension(20, 20);
	
	
	public static final int 
		MATRIX_X = 10;
	public static final int 
		MATRIX_Y = 20;
	
	
	public static final int 
		NEXT_X_Y = 4;
	
	
	public static final int
		GRAVITY_DEFAULT_DELAY = 2100;
	public static final int
		GRAVITY_SPEEDUP_DELAY = 50;
	public static final int
		GRAVITY_REDUCTION_PER_LEVEL = 200;
	
	
	public static final int
		CONTROLLER_DEFAULT_DROP = KeyEvent.VK_SPACE;
	public static final int
		CONTROLLER_DEFAULT_LEFT = KeyEvent.VK_LEFT;
	public static final int
		CONTROLLER_DEFAULT_RIGHT = KeyEvent.VK_RIGHT;
	public static final int
		CONTROLLER_DEFAULT_SPEEDUP = KeyEvent.VK_DOWN;
	public static final int
		CONTROLLER_DEFAULT_ROTATE = KeyEvent.VK_UP;
	
	public static final Dimension
		VIEW_DATA_DIM = new Dimension(120,20);
	
	public static final Dimension WIN_PREFERRED_DIM = new Dimension(800,500);
	
	public static final Dimension WIN_POSTGAME_GRID_DIM = new Dimension(800,120);
	 
	public final static ImageIcon IMAGE_WELCOME =
		new ImageIcon(Menu.class.getResource("multitris.JPG"));
	//public final static ImageIcon IMAGE_SINGLE_BUTTON =
	//	new ImageIcon(GameConstants.class.getResource("./view/singlePlayer.JPG"));
	//public final static ImageIcon IMAGE_MULTI_BUTTON =
	//	new ImageIcon(GameConstants.class.getResource("./view/multi.JPG"));
	//public final static ImageIcon IMAGE_EXIT_BUTTON =
	//	new ImageIcon(GameConstants.class.getResource("./view/exit.JPG"));
	public final static ImageIcon IMAGE_ICON =
		new ImageIcon(Menu.class.getResource("winlogo.png"));
	public static final Icon IMAGE_DEFAULT_BUTTON = 
		new ImageIcon(Menu.class.getResource("button.png"));
	//public static final String START_BUTTON_PATH =
	//	LobbyPanel.class.getResource("./start.jpg").getPath();
	
	public final static int SURVIVAL_BONUS_1 = 20000;
	public final static int SURVIVAL_BONUS_2 = 10000;
	public final static int SURVIVAL_BONUS_3 = 5000;
	public final static int SURVIVAL_BONUS_4 = 0;
	
	public final static Font FONT_DEFAULT_BUTTON = initDefaultFont();
	
	private static Font initDefaultFont() {
		Font f = new Font("Dialog", Font.BOLD, 14);
		InputStream str = GameConstants.class.getResourceAsStream("game_over.ttf");
		boolean error = false;
		
		try {
			f = Font.createFont(
					Font.TRUETYPE_FONT, 
					str);
			GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 
			ge.registerFont(f);
		} 
		catch (FileNotFoundException e) { error = true;
			e.printStackTrace();
		} 
		catch (FontFormatException e) { error = true;
			e.printStackTrace();
		} 
		catch (IOException e) { error = true;
			e.printStackTrace();
		}
		if(error) {
			SwingUtils.infoMessage(null, 
				"Could not load font, using default.", 
				"Font error");
			return f;
		}
		
		return new Font(f.getFontName(), Font.BOLD, 14);//32);
	}
}
